package com.xiaoyu.lanling.feature.conversation

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.xiaoyu.base.utils.MMKVUtil
import com.xiaoyu.base.utils.extensions.setOnClickDebounceListener
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.BaseDialogFragment
import com.xiaoyu.lanling.common.Constant
import kotlinx.android.synthetic.main.main_chat_reward_tip_dialog.*

class RewardTipDialog : BaseDialogFragment() {

    companion object {
        private val TAG = RewardTipDialog::class.java.simpleName

        fun show(fragmentManager: FragmentManager) {
            val dialogFragment = (fragmentManager.findFragmentByTag(TAG) as? RewardTipDialog) ?: RewardTipDialog()
            dialogFragment.show(fragmentManager, TAG)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogFullScreenDimStyle)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.main_chat_reward_tip_dialog, container, false)
    }

    override fun onViewCreatedSafelyAfterAppFinishInit(view: View, savedInstanceState: Bundle?) {
        super.onViewCreatedSafelyAfterAppFinishInit(view, savedInstanceState)
        initBind()
        initData()
    }

    private fun initBind() {
        button.setOnClickDebounceListener { dismiss() }
    }

    private fun initData() {
        MMKVUtil.get()?.putBoolean(Constant.MMKVKey.KEY_HAS_SHOW_REWARD_TIP_DIALOG, true)
    }
}